package jvm;

public class ThreadDemo {

  static boolean flag = false;

  public static void main(String[] args) {

    Mex mex = new Mex();

    Thread thread1 = new Thread(new Runnable() {
      @Override
      public void run() {
        while (true) {
//          synchronized (mex) {
          if (!mex.flag) {
            System.out.println("flage = false");
          } else {
            break;
          }
//          }
        }
      }
    });

    thread1.start();

    //后发生
    Thread thread = new Thread(new Runnable() {
      @Override
      public void run() {
        mex.flag = true;
        System.out.println("flag = true");
      }
    });

    thread.start();

  }

  static class Mex {
    boolean flag = false;
  }

}
